package com.alibaba.middleware.hsf.guide.serialize.fst;

import com.taobao.hsf.io.serialize.Serializer;
import com.taobao.hsf.io.stream.Stream;

import org.nustaq.serialization.FSTConfiguration;

/**
 * @author weipeng2k 2018年03月14日 上午10:49:27
 */
public class FstSerializer implements Serializer {

    private static FSTConfiguration configuration = FSTConfiguration.createDefaultConfiguration();

    @Override
    public String name() {
        return "fst";
    }

    @Override
    public byte type() {
        return 111;
    }

    @Override
    public byte[] serialize(Object object, Stream stream) throws Exception {
        return configuration.asByteArray(object);
    }

    @Override
    public Object deserialize(byte[] bytes, Class<?> type, Stream stream) throws Exception {
        return configuration.asObject(bytes);
    }

    @Override
    public Object deserialize(byte[] bytes, Stream stream) throws Exception {
        return configuration.asObject(bytes);
    }
}
